import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baidu.unbiz.fluentvalidator.Result;
import com.tc.qichacha.validator.BaseResponseValidator;
import com.tc.qichacha_new.detail.Details;
import com.tc.qichacha_new.stock.CompanyEquityShare;
import com.tc.qichacha_new.stock.EquityShareDetail;
import com.tc.qichacha_new.stock.StockResult;
import com.tc.utils.ToolsHt;
import com.tc.utils.image.table.Table;
import com.tc.utils.image.tree.RectNode;
import lombok.extern.java.Log;
import org.junit.Test;
import java.util.List;

@Log
public class test5New {
    @Test
    public void demo1() throws Exception {
        JSONObject jsonObject = JSON.parseObject(ToolsHt.respond("E:/json_.txt"));
        Object status = jsonObject.get("Status");
        if ("200".equals(status)) {
            System.out.println("响应成功");
        }
        Object result = jsonObject.get("Result");
        if (result == null) return;
        JSONObject resultJ = (JSONObject) result;
        //ToolsHt.eachKeySet(resultJ);
        Object equityShareDetail = resultJ.get("EquityShareDetail");
        ToolsHt.eachKeySet(equityShareDetail);
        CompanyEquityShare companyEquityShare = JSON.parseObject(ToolsHt.respond("E:/json_.txt"), CompanyEquityShare.class);
        StockResult result1 = companyEquityShare.getResult();
        List<EquityShareDetail> equityShareDetail1 = result1.getEquityShareDetail();
        RectNode rectNode = new RectNode(result1.getCompanyName());
        for (EquityShareDetail temp:equityShareDetail1) {
            rectNode.addChild(ToolsHt.eachChildren_(temp));
        }
        rectNode.write("d:/image.jpg");
        System.out.println(companyEquityShare);
    }

    @Test
    public void demo2() throws Exception {
        JSONObject jsonObject = JSON.parseObject(ToolsHt.respond("E:/json_1.txt"));
        Object status = jsonObject.get("Status");
        if ("200".equals(status)) {
            System.out.println("响应成功");
        }
        Object result = jsonObject.get("Result");
        if (result == null) return;
        JSONObject resultJ = (JSONObject) result;
        //ToolsHt.eachKeySet(resultJ);
        Object partners = resultJ.get("Partners");
        /*System.out.println("股东信息");
        ToolsHt.eachKeySet(partners);*/
        Object employees = resultJ.get("Employees");
       /* System.out.println("主要人员");
        ToolsHt.eachKeySet(employees);*/
        Object branches = resultJ.get("Branches");
        /*System.out.println("分支机构");
        ToolsHt.eachKeySet(branches);*/
        Object changeRecords = resultJ.get("ChangeRecords");
        /*System.out.println("变更信息");
        ToolsHt.eachKeySet(changeRecords);*/
        JSONObject contactInfo = (JSONObject) resultJ.get("ContactInfo");
        /*System.out.println("联系信息");
        ToolsHt.eachKeySet(contactInfo);*/
        Object webSite = contactInfo.get("WebSite");
        /*System.out.println("网站信息");
        ToolsHt.eachKeySet(webSite);*/
        Object Industry = resultJ.get("Industry");
        System.out.println("行业信息");
        ToolsHt.eachKeySet(Industry);

    }

    @Test
    public void demo3() throws Exception {
        JSONObject jsonObject = JSON.parseObject(ToolsHt.respond("E:/json2.txt"));
        Object status = jsonObject.get("Status");
        if ("200".equals(status)) {
            System.out.println("响应成功");
        }
        Object result = jsonObject.get("Result");
        if (result == null) return;
        JSONObject resultJ = (JSONObject) result;
        //ToolsHt.eachKeySet(resultJ);
        JSONArray breakThroughList = (JSONArray) resultJ.get("BreakThroughList");
        /*System.out.println("受益所有人列表");
        ToolsHt.eachKeySet(breakThroughList);*/
        Object detailInfoList = ((JSONObject) breakThroughList.get(0)).get("DetailInfoList");
        System.out.println("详情");
        ToolsHt.eachKeySet(detailInfoList);
    }


    @Test
    public void demo5() throws Exception {
        Details detail = JSON.parseObject(ToolsHt.respond("E:/json_1.txt"), Details.class);
        Result validatResult = ToolsHt.validateByCustomAndJSR303(detail, new BaseResponseValidator());
        if (!validatResult.isSuccess()) {
            log.info(validatResult.toString());
            return;
        }
        System.out.println(detail);
        if ("200".equals(detail.getStatus())) {
            System.out.println("响应成功");
        }
        com.tc.qichacha_new.detail.Result result1 = detail.getResult();
        Table table = new Table(2);
        table.appendRow().setCellText("企业名称").setCellText(result1.getName());
        table.appendRow().setCellText("法人名称").setCellText(result1.getOper().getName());
        table.appendRow().setCellText("成立日期").setCellText(result1.getStartDate());
        table.appendRow().setCellText("企业状态").setCellText(result1.getStatus());
        table.appendRow().setCellText("注册号").setCellText(result1.getNo());
        table.appendRow().setCellText("社会统一信用代码").setCellText(result1.getCreditCode());
        table.write("d:/table.jpg");
    }
    /* @Autowired
     private Validator validator;*/


}
